﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace scmsByAspdNet.cotro.admin {
  /// <summary>
  /// addTeacherCourse 的摘要说明
  /// </summary>
  public class addTeacherCourse : IHttpHandler {

    public void ProcessRequest(HttpContext context) {
      context.Response.ContentType = "text/plain";
      //获取参数
      string tid = context.Request["tid"];
      string courses = context.Request["courses"];
      string[] course = courses.Split(',');
      //生成sql
      string sql = "";
      foreach(string cour_id in course) {
        if (cour_id == "") { continue; }
        sql += $"INSERT INTO sc_cour_tea VALUES({cour_id},{tid},1,0);";
      }

      SqlConnection conn = new SqlConnection("Data Source=106.54.69.143;database=scms;uid=sa;pwd=Aspdotnet666");
      conn.Open();
      SqlCommand sql_rows = new SqlCommand(sql, conn);
      int res = sql_rows.ExecuteNonQuery();
      conn.Close();
      //返回数据
      context.Response.StatusCode = 200;
      context.Response.Write($"{{\"line\":{res}}}");
    }

    public bool IsReusable {
      get {
        return false;
      }
    }
  }
}